package com.burgeon.backend.Rest.Tool;
/**
 * 获取卡类型
 */


import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class GetVIPType extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public GetVIPType(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     * @return
     */

    public ArrayList<String> getData() throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(),url);
        System.err.println(str);
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList<String> data = new ArrayList<String>();

        for (int i=0;i<jsonArray.length();i++){

           data.add(jsonArray.getJSONArray(i).getString(0));
        }

        return data;
    }

    private MultiValueMap Data( ) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("NAME");
        columns.add("DISCOUNT");//折扣
        columns.add("INTEGRALRATE");//积分比例


        params.put("columns", columns);
        params.put("table", "C_VIPTYPE");//表名


        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        GetVIPType g = new GetVIPType("59.110.28.94:90","nea@burgeon.com.cn","burgeon55321");
        try {
            System.err.println(g.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
